package kom;

import java.util.ArrayList;
import java.util.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Ziden
 */
public class ThreadSafeList<Type> {

    public boolean locked = false;
    private List<Type> theList = new ArrayList<Type>();
    private List<Type> buffer = new ArrayList<Type>();

    public void save() {
        locked = true;
    }

    public boolean isUpdated() {
        return locked;
    }

    public List<Type> getList() {
        if (locked) {
            theList.clear();
            theList.addAll(buffer);
            buffer.clear();
            locked = false;
        }
        return theList;
    }
    // render

    // tick
    public void add(Type t) {
        buffer.add(t);
    }
}
